public class GetIdJiaoYan {
    private static final int[] a = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
    private static final String[] w = { "1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2" };
    @SuppressWarnings("null")
	public static int isIdCard(String idCardNo) {
    	if(idCardNo!=null||idCardNo.length()!=0){
           if (idCardNo.length()==18){
            	if(idCardNo.substring(0,17).matches("\\d{17}")&&idCardNo.substring(17).matches("[\\dXx]")){
            		if(idCardNo.substring(6,14).matches("^((((1[6-9]|[2-9]\\d)\\d{2})(0?[13578]|1[02])(0?[1-9]|[12]\\d|3[01]))|(((1[6-9]|[2-9]\\d)\\d{2})(0?[13456789]|1[012])(0?[1-9]|[12]\\d|30))|(((1[6-9]|[2-9]\\d)\\d{2})0?2(0?[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))0?229))$")){
            		    if(idCardNo.substring(17).equalsIgnoreCase(getCheckNumber(idCardNo))){
                           return 0;
            		   }else{
            		      return 5;
            		   }
            		}else{
            			return 4;
            		}
            	}else{
            		return 3;
            	}
           } else {
            return 2;
           }
    	}else{
    		return 1;
    	}
    }
    public static String getCheckNumber(String idCardNo) {
            int sigma = 0;
            for (int i = 0; i < 17; i++) {
                int ai = Integer.parseInt(idCardNo.substring(i, i + 1));
                int wi = a[i];
                sigma += ai * wi;
            }
            return w[sigma % 11];
    }     
    public static void main(String[] args) {
    	System.out.println(isIdCard("142725198406112421"));
    }
}

